package com.wmcsk.dl.util;


import android.content.Context;
import android.content.SharedPreferences;

/**
 * 
 * @author 刘红亮  2015年7月1日 下午2:10:24
 * SharedPreferences工具类
 *
 */
public class SPUtil {
	/**
	 * SP的名字
	 */
	public static final String SP_NAME = "sibuSp";
	
	/**
     * 保存的用户信息
     */
    public static final String USERINFO = "userInfo";
    
    /**
     * token保存的时间
     */
    public static final String TOKEN_TIME = "token_time";
    
    
	/**
	 * 本地保存插件信息相关
	 */
	public static final String PLUGINMAP="pluginMap";
    
	/**
	 * 
	 * @param key 键
	 * @param value 值
	 */
	public static void saveString(Context context, String key, String value) {
		SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
		sp.edit().putString(key, value).commit();
	}

	/**
	 * 
	 * @param context
	 * @param key
	 * @param defValue
	 * @return
	 */
	public static String getString(Context context, String key, String defValue) {
		SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
		return sp.getString(key, defValue);
	}

	/**
	 * 
	 * @param context
	 * @param key
	 * @param value
	 */
	public static void saveInt(Context context, String key, int value) {
		SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
		sp.edit().putInt(key, value).commit();
	}

	/**
	 * 
	 * @param context
	 * @param key
	 * @param defValue
	 * @return
	 */
	public static int getInt(Context context, String key, int defValue) {
		SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
		return sp.getInt(key, defValue);
	}
	/**
	 * 
	 * TODO 保存长整形数据
	 * @param @param context
	 * @param @param key
	 * @param @param value
	 * @throw 
	 * @return void
	 */
	
	public static void saveLong(Context context , String key, long value){
		SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
		sp.edit().putLong(key, value).commit();
	}
	/**
	 * 
	 * TODO<取长整形数据> 
	 * @param @param context
	 * @param @param key
	 * @param @param defValue
	 * @param @return
	 * @throw 
	 * @return long
	 */
	public static long getLong(Context context, String key, long defValue){
		SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
		return sp.getLong(key, defValue);
	}
    /**
     * @param context
     * @param key
     * @param value
     */
    public void saveBoolean(Context context, String key, boolean value) {
    	SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
        sp.edit().putBoolean(key, value).commit();
    }

    /**
     * @param context
     * @param key
     * @param defValue
     * @return
     */
    public boolean getBoolean(Context context, String key, boolean defValue) {
    	SharedPreferences sp = context.getSharedPreferences(SP_NAME, 0);
        return sp.getBoolean(key, defValue);
    }
}
